import java.util.ArrayList;
import java.util.List;

/**
 * Created by losor on 2016/10/13.
 */
public class _387_FirstUniqueCharacterinaString {
    public static void main(String[] args) {
        System.out.println(firstUniqChar("loveleetcode"));
    }

    public static int firstUniqChar(String s) {
        StringBuilder stringBuilder = new StringBuilder(s);
        int charCount[] = new  int[26];

        for (int i = 0; i < 26; i++) {
            charCount[i] = -1;
        }
        for (int i = 0; i < stringBuilder.length(); i++) {
            if(charCount[stringBuilder.charAt(i)-'a']==-1){
                charCount[stringBuilder.charAt(i)-'a'] = i;
            }
            else{
                charCount[stringBuilder.charAt(i)-'a'] = -2;
            }
        }
        int min = -1;
        for (int i : charCount
                ) {
            if(i != -1 && i != -2){
                if(min == -1){
                    min = i;
                }
                else{
                 if (min>i){
                     min = i;
                }
            }
        }
        }
        return min;
    }
}
